﻿package kliment.controls.mediaplayer.skin {
	import flash.display.DisplayObject;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.geom.Rectangle;
	import flash.media.Video;
	import kliment.display.draw.shape.RectangleShape;
	import kliment.display.MovieClipButton;
	import kliment.utils._Sprite;
	import kliment.utils.Transformation;
	
	/**
	 * ...
	 * @author Kliment
	 * 
	 * class name: kliment.controls.mediaplayer.skin.ViewPort
	 */
	public class ViewPort extends MovieClipButton {
		private var _space:Shape;
		private var _mask:Shape;
		private var _cell:Sprite;
		private var _videoLayout:Sprite;
		private var _currentVideo:Video;
		
		public function ViewPort() {
			_cell = new Sprite();
			var vp_size:Rectangle = new Rectangle(0, 0, 100, 100);
			_space = new RectangleShape(vp_size);
			_mask =  new RectangleShape(vp_size);
			_cell.mask = _mask;
			super.addChild(_space);
			super.addChild(_cell);
			super.addChild(_mask);
			
			_videoLayout = new Sprite();
			_cell.addChild(_videoLayout);
		}
		
		public function setVideo(value:Video):void {
			if (_currentVideo)
				_Sprite.remove(_currentVideo);
			_currentVideo = value;
			_videoLayout.addChild(value);
			update();
		}
		
		public function update():void {
			if (_currentVideo)
				Transformation.to(_videoLayout, Transformation.putInSpace(_videoLayout, width, height, false, true));
		}
		
		override public function get width():Number { return _space.width }
		override public function set width(value:Number):void {
			_space.width = 
			_mask.width = value;
			update();
		}
		
		override public function get height():Number { return _space.height }
		override public function set height(value:Number):void {
			_space.height = 
			_mask.height = value;
			update();
		}
		
		override public function addChild(child:DisplayObject):DisplayObject {
			return child;
		}
		
		override public function addChildAt(child:DisplayObject, index:int):DisplayObject {
			return child;
		}
		
		override public function removeChild(child:DisplayObject):DisplayObject {
			return child;
		}
		
		override public function removeChildAt(index:int):DisplayObject {
			return null;
		}
	}

}